package com.spsy.pay.controller;

import com.spsy.common.core.domain.R;
import com.spsy.pay.domain.PaymentOrder;
import com.spsy.pay.order.WeiXinUtil;
import com.spsy.pay.service.IPaymentOrderService;
import com.spsy.pay.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.UUID;

@RestController
@RequestMapping("/pay")
public class PayOptsController {


    @Autowired
    private IPaymentOrderService iPaymentOrderService;


    @PostMapping("create")
    public String create(@RequestBody OrderVo orderVo) throws Exception {

        PaymentOrder paymentOrder = PaymentOrder.builder()
                //.createTime(new Date())
                .orderNo(UUID.randomUUID().toString())
                .notifyUrl("Url")
                .errorMessage("1")
                .expireTime(new Date())
                .payAmount(new BigDecimal(12))
                .payMethod("payMethod")
                .userIp("ip")
                .notifyStatus(1)
                .payTime(new Date())
                .build();

        int save = iPaymentOrderService.insertPaymentOrder(paymentOrder);

        String codeUrl = WeiXinUtil.payOrder(orderVo.getOrderId());

        return codeUrl;
    }



}
